<?php
/********************************************************************************
 * File: recent.php
 * Desc: Recent page shows all photos ordered by date descending with 54 photos
 *       shown on a page.
 * Args: page - int optional.  
 *          The page number to show.  If none, show the first page with the
 *          most recent 54 photos.
 ********************************************************************************/
require_once("inc/header.php");

$photos = "";
$page = $_GET['page'] ? $_GET['page'] : 1;
$set = $_GET['setId'];
$favorites = $_GET['favorites'];
$tag = $_GET['tag'];
$size = $_GET['size'] ? $_GET['size'] : "Square";
$count = $_GET['count'] ? $_GET['count'] : 54;
$prev = $page - 1;
$next = $page + 1;
$prevLink = "";
$nextLink = "";

if ($set) { // show photos from this set
   $photoSet = $f->photosets_getInfo($set);
   $title = "sets // " . htmlentities($photoSet['title'], ENT_QUOTES);
   $photos = $f->photosets_getPhotos($set, "original_format,date_taken,date_upload", "", $count, $page);   
   $prevLink = "setId=" . $set . "&page=" . $prev . "&count=" . $count . "&size=" . $size;
   $nextLink = "setId=" . $set. "&page=" . $next . "&count=" . $count . "&size=" . $size;
}
else if ($favorites) { // show favorites
   $title = "Favorites";
   $photos = $f->favorites_getPublicList($config_flickrUserId, "date_taken,date_upload", $count, $page);
   $prevLink = "favorites" . "&page=" . $prev . "&count=" . $count . "&size=" . $size;
   $nextLink = "favorites" . "&page=" . $next . "&count=" . $count . "&size=" . $size;
}
else if ($tag) { // show photos with this tag
   $photoSearchParams = array(
      "user_id"=>$config_flickrUserId, 
      "tags"=>$tag, 
      "extras"=>"original_format,date_taken,date_upload", 
      "per_page"=>$count, 
      "page"=>$page);
      
   $title = "tags // " . $tag;
   $photos = $f->photos_search($photoSearchParams);   
   $prevLink = "tag=" . $tag . "&page=" . $prev . "&count=" . $count . "&size=" . $size;
   $nextLink = "tag=" . $tag . "&page=" . $next . "&count=" . $count . "&size=" . $size;
}
else { // show my recent photos
   $photoSearchParams = array(
      "user_id"=>$config_flickrUserId, 
      "tags"=>$config_flickrTags, 
      "extras"=>"original_format,date_taken,date_upload", 
      "per_page"=>$count, 
      "page"=>$page);
      
   $title = "Recent";
   $photos = $f->photos_search($photoSearchParams);   
   $prevLink = "page=" . $prev . "&count=" . $count . "&size=" . $size;
   $nextLink = "page=" . $next . "&count=" . $count . "&size=" . $size;
}

foreach ($photos['photo'] as $photo) {
   $datePosted = date("F j, Y", $photo['dateupload']);
   $photo_thumbs .=
   "<a href='" . $f->buildPhotoURL($photo, "") . "' rel='lightbox[recent]' title='" . htmlentities($photo['title'], ENT_QUOTES) . " | " . $datePosted . "' alt='' name='" . $photo['id'] . "'>" .
      "<img class='thumbnail' src='" . $f->buildPhotoURL($photo, $size) . "' title='" . htmlentities($photo['title'], ENT_QUOTES) . "::" . $datePosted . "' alt=''/>" .
   "</a>";
}
?>

<div id='page_header'>
   <span id='page_title'><?php echo $title; ?></span>
   <span id='page_nav'>
      <?php if (0 < $prev) { ?>
      <a href='recent.php?<?php echo $prevLink; ?>'>prev </a>
      <?php } ?>
      <?php if ($next<= $photos['pages']) { ?>
      <a href='recent.php?<?php echo $nextLink; ?>'>next</a>
      <?php } ?>
   </span>
</div>

<div id='page'>
   <div id='thumbnail_container'>
      <?php echo $photo_thumbs; ?>
   </div>
</div>

<!-- Javascript effects -->
<script type='text/javascript' src='js/mootools.v1.11.js'></script>
<script type='text/javascript' src='js/slimbox.js'></script>
<link rel='stylesheet' href='css/slimbox.css' type='text/css' media='screen' />
<script type='text/javascript'>  
   window.addEvent('domready', function(){
      /**
      * Photo tool tip effect
      */
      var PhotoNav = new Tips($$('.thumbnail'));
   });
</script>

<?php 
require_once("inc/footer.php"); 
?>
